//
//  YPWorldView.m
//  WHISPER
//
//  Created by lanou3g on 15/12/22.
//  Copyright © 2015年 王艳苹. All rights reserved.
//

#import "YPWorldView.h"
#import "UIView+Extention.h"

@implementation YPWorldView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        //设置弹出View的背景颜色
        self.backgroundColor = [UIColor clearColor];
        [self showInWindow];
    }
    return self;
}


+ (instancetype)show{
    return [[self alloc]init];
}
- (void)dismiss{
    [self removeFromSuperview];
}
//展示内容
- (void)showInWindow{
    //获取最上层的窗口
    UIWindow *window = [[UIApplication sharedApplication].windows lastObject];
    [window addSubview:self];
    
    UIView *view = [[UIView alloc]initWithFrame:CGRectMake(0,64, self.width, 150)];
    view.backgroundColor = [UIColor colorWithRed:0.5 green:0.5 blue:0.5 alpha:0.8];
    [self addSubview:view];
    //设置内容
    float width = (self.width - 80) / 2;
    _little = [UIButton buttonWithType:UIButtonTypeSystem];
    _little.frame = CGRectMake(30,30,width,30);
    [_little setTitle:@"A-" forState:UIControlStateNormal];
    _little.backgroundColor = [UIColor yellowColor];
    [view addSubview:_little];
    
    _big = [UIButton buttonWithType:UIButtonTypeSystem];
    [_big setTitle:@"A+" forState:UIControlStateNormal];
    _big.frame = CGRectMake(CGRectGetMaxX(_little.frame) +20,30,width,30);
    _big.backgroundColor = [UIColor yellowColor];
    [view addSubview:_big];
    
    _white = [UIButton buttonWithType:UIButtonTypeSystem];
    [_white setTitle:@"白天" forState:UIControlStateNormal];
    _white.frame = CGRectMake(CGRectGetMinX(_little.frame),CGRectGetMaxY(_little.frame) + 20,width,30);
    _white.backgroundColor = [UIColor yellowColor];
    [view addSubview:_white];
    
    _black = [UIButton buttonWithType:UIButtonTypeSystem];
    [_black setTitle:@"夜间" forState:UIControlStateNormal];
    _black.frame = CGRectMake(CGRectGetMinX(_big.frame),CGRectGetMaxY(_big.frame) + 20,width,30);
    _black.backgroundColor = [UIColor yellowColor];
    [view addSubview:_black];
}
 - (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
     self.isOpen = !_isOpen;
     [self dismiss];
}
@end
